package com.afc.qua;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * JdbcUtil class.
 */
final public class JdbcUtil
{
  /**
   * JdbcUtil constructor.
   */
  private JdbcUtil()
  {
  }

  /**
   * @return connection.
   */
  static public Connection getConnection()
  {
    try
    {
      return DriverManager.getConnection(url, login, password);
    }
    catch (SQLException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return null;
    }
  }

  /**
   * driver.
   */
  static private String driver;
  /**
   * url.
   */
  static private String url;
  /**
   * login.
   */
  static private String login;
  /**
   * password.
   */
  static private String password;
  static
  {
    Properties properties = new Properties();
    try
    {
      properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("qua.properties"));
      driver = properties.getProperty("driver");
      url = properties.getProperty("url");
      login = properties.getProperty("login");
      password = properties.getProperty("password");
      Class.forName(driver);
    }
    catch (IOException | ClassNotFoundException e)
    {
      e.printStackTrace();
    }
  }
}
